﻿using System;
using System.Data;

using SqlHelperForCry.Common;

namespace Torch.WL.Entity
{
    [Table("Tb_EM", "EMId", "Torch.WL.ConnectionString")]
    public class Tb_EM : Info
    {
        #region SQL column name consts
        public const string SQLCOL_EMID = "EMId";
        public const string SQLCOL_PUBLISHYEAR = "publishYear";
        public const string SQLCOL_PERIOD = "period";
        public const string SQLCOL_TITLE = "title";
        public const string SQLCOL_MEMO = "Memo";
        public const string SQLCOL_IMAGELIST = "imagelist";
        public const string SQLCOL_IMAGECOUNT = "imageCount";
        public const string SQLCOL_CREATETIME = "createTime";
        #endregion


        #region Contructors
        /// <summary>
        /// Construct empty entity
        /// </summary>
        public Tb_EM() { }

        /// <summary>
        /// Construct entity by primary key, other fields will be assigned by 
        /// "Load" method.
        /// </summary>
        public Tb_EM(int EMId)
        {
            this.EMId = EMId;
        }
        #endregion

        public override void Init(DataRow row)
        {
            EMId = (int)ObjectType.IntTypeHelper.Read(row[SQLCOL_EMID]);
            publishYear = (int)ObjectType.IntTypeHelper.Read(row[SQLCOL_PUBLISHYEAR]);
            period = (int)ObjectType.IntTypeHelper.Read(row[SQLCOL_PERIOD]);
            title = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_TITLE]);
            Memo = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_MEMO]);
            imagelist = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_IMAGELIST]);
            imageCount = (int)ObjectType.IntTypeHelper.Read(row[SQLCOL_IMAGECOUNT]);
            createTime = (DateTime)ObjectType.DateTimeTypeHelper.Read(row[SQLCOL_CREATETIME]);
        }

        #region Properties
        #region Property <int> EMId
        [Property("EMId", 4, SqlDbType.Int, true, true)]
        public int EMId
        {
            get { return _EMId; }
            set { _EMId = value; }
        }
        private int _EMId = int.MinValue;
        #endregion

        #region Property <int> publishYear
        [Property("publishYear", 4, SqlDbType.Int, false, false)]
        public int publishYear
        {
            get { return _publishYear; }
            set { _publishYear = value; }
        }
        private int _publishYear = int.MinValue;
        #endregion

        #region Property <int> period
        [Property("period", 4, SqlDbType.Int, false, false)]
        public int period
        {
            get { return _period; }
            set { _period = value; }
        }
        private int _period = int.MinValue;
        #endregion

        #region Property <string> title
        [Property("title", 200, SqlDbType.VarChar, false, false)]
        public string title
        {
            get { return _title; }
            set { _title = value; }
        }
        private string _title = null;
        #endregion

        #region Property <string> Memo
        [Property("Memo", 2147483647, SqlDbType.Text, false, false)]
        public string Memo
        {
            get { return _Memo; }
            set { _Memo = value; }
        }
        private string _Memo = null;
        #endregion

        #region Property <string> imagelist
        [Property("imagelist", 2147483647, SqlDbType.Text, false, false)]
        public string imagelist
        {
            get { return _imagelist; }
            set { _imagelist = value; }
        }
        private string _imagelist = null;
        #endregion

        #region Property <int> imageCount
        [Property("imageCount", 4, SqlDbType.Int, false, false)]
        public int imageCount
        {
            get { return _imageCount; }
            set { _imageCount = value; }
        }
        private int _imageCount = int.MinValue;
        #endregion

        #region Property <DateTime> createTime
        [Property("createTime", 16, SqlDbType.DateTime, false, false)]
        public DateTime createTime
        {
            get { return _createTime; }
            set { _createTime = value; }
        }
        private DateTime _createTime = DateTime.MinValue;
        #endregion
        #endregion


        public bool LoadByIdentity(int EMId)
        {
            return DataAccess.SelectByIdentity(this, Convert.ToInt64(EMId));
        }


        public bool DeleteByIdentity()
        {
            return DataAccess.DeleteByIdentity(this);
        }
    }
}
